#include "stdafx.h"
#include "Logger.h"

using namespace mcore;

#define LOGFILE_PATH "LOGS.txt"

Logger::Logger()
{
	std::ofstream logfile("LOGS.txt");
	logfile << "OK logger created\n";
}

Logger & Logger::get()
{
	static Logger l;
	return l;
}

Logger::~Logger(void)
{
}

void Logger::log(std::string message, LogType type)
{
	std::ofstream logfile(LOGFILE_PATH, std::ios_base::app);

	switch(type)
	{
	case LOG_TYPE_OK:
		logfile << "OK " << message << "\n";
		break;

	case LOG_TYPE_WARNING:
		logfile << " WARNING " << message << "\n";
		break;

	case LOG_TYPE_ERROR:
		logfile << "\n############# ERROR #############\n" << message << "\n#################################\n\n";
		break;
	}
}

std::ofstream & Logger::getLogStream(LogType type)
{
	mLogfile.open(LOGFILE_PATH, std::ios_base::app);

	switch(type)
	{
	case LOG_TYPE_OK:
		mLogfile << "OK ";
		break;

	case LOG_TYPE_WARNING:
		mLogfile << " WARNING ";
		break;

	case LOG_TYPE_ERROR:
		mLogfile << "\n############# ERROR #############\n";
		break;
	}

	return mLogfile;
}

void Logger::endLogStream(LogType type)
{
	if(type == LOG_TYPE_ERROR)
		mLogfile << "\n#################################\n\n";
	else
		mLogfile << "\n";

	mLogfile.close();
}
